from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-03 14:07:06.176531
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 03, Nov, 2022
Time: 14:07:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8684
Nobs: 829.000 HQIC: -51.1843
Log likelihood: 10800.6 FPE: 4.84849e-23
AIC: -51.3808 Det(Omega_mle): 4.35251e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296445 0.051153 5.795 0.000
L1.Burgenland 0.109349 0.035019 3.123 0.002
L1.Kärnten -0.106589 0.018650 -5.715 0.000
L1.Niederösterreich 0.211110 0.073264 2.882 0.004
L1.Oberösterreich 0.098730 0.069920 1.412 0.158
L1.Salzburg 0.250816 0.037219 6.739 0.000
L1.Steiermark 0.036114 0.048757 0.741 0.459
L1.Tirol 0.107078 0.039545 2.708 0.007
L1.Vorarlberg -0.058723 0.034041 -1.725 0.085
L1.Wien 0.060062 0.062643 0.959 0.338
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068500 0.105655 0.648 0.517
L1.Burgenland -0.031593 0.072331 -0.437 0.662
L1.Kärnten 0.047224 0.038520 1.226 0.220
L1.Niederösterreich -0.171122 0.151322 -1.131 0.258
L1.Oberösterreich 0.375080 0.144415 2.597 0.009
L1.Salzburg 0.288441 0.076875 3.752 0.000
L1.Steiermark 0.105946 0.100704 1.052 0.293
L1.Tirol 0.316073 0.081679 3.870 0.000
L1.Vorarlberg 0.023670 0.070309 0.337 0.736
L1.Wien -0.015498 0.129386 -0.120 0.905
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194920 0.026423 7.377 0.000
L1.Burgenland 0.091694 0.018089 5.069 0.000
L1.Kärnten -0.008685 0.009633 -0.902 0.367
L1.Niederösterreich 0.265792 0.037844 7.023 0.000
L1.Oberösterreich 0.117232 0.036116 3.246 0.001
L1.Salzburg 0.050367 0.019225 2.620 0.009
L1.Steiermark 0.017413 0.025185 0.691 0.489
L1.Tirol 0.095893 0.020427 4.694 0.000
L1.Vorarlberg 0.057751 0.017583 3.284 0.001
L1.Wien 0.118726 0.032358 3.669 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105100 0.027063 3.884 0.000
L1.Burgenland 0.046194 0.018527 2.493 0.013
L1.Kärnten -0.017007 0.009867 -1.724 0.085
L1.Niederösterreich 0.194927 0.038760 5.029 0.000
L1.Oberösterreich 0.284589 0.036991 7.693 0.000
L1.Salzburg 0.118364 0.019691 6.011 0.000
L1.Steiermark 0.102387 0.025795 3.969 0.000
L1.Tirol 0.120403 0.020921 5.755 0.000
L1.Vorarlberg 0.070282 0.018009 3.903 0.000
L1.Wien -0.025919 0.033141 -0.782 0.434
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121317 0.048968 2.477 0.013
L1.Burgenland -0.049595 0.033523 -1.479 0.139
L1.Kärnten -0.040470 0.017853 -2.267 0.023
L1.Niederösterreich 0.168771 0.070133 2.406 0.016
L1.Oberösterreich 0.137245 0.066932 2.051 0.040
L1.Salzburg 0.284970 0.035629 7.998 0.000
L1.Steiermark 0.034019 0.046673 0.729 0.466
L1.Tirol 0.166467 0.037856 4.397 0.000
L1.Vorarlberg 0.105878 0.032586 3.249 0.001
L1.Wien 0.073093 0.059967 1.219 0.223
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059591 0.038856 1.534 0.125
L1.Burgenland 0.040893 0.026600 1.537 0.124
L1.Kärnten 0.049851 0.014166 3.519 0.000
L1.Niederösterreich 0.226098 0.055650 4.063 0.000
L1.Oberösterreich 0.274370 0.053110 5.166 0.000
L1.Salzburg 0.055358 0.028272 1.958 0.050
L1.Steiermark -0.007599 0.037035 -0.205 0.837
L1.Tirol 0.153318 0.030038 5.104 0.000
L1.Vorarlberg 0.069760 0.025857 2.698 0.007
L1.Wien 0.079172 0.047583 1.664 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178832 0.046500 3.846 0.000
L1.Burgenland -0.004358 0.031834 -0.137 0.891
L1.Kärnten -0.061322 0.016953 -3.617 0.000
L1.Niederösterreich -0.083057 0.066599 -1.247 0.212
L1.Oberösterreich 0.186508 0.063559 2.934 0.003
L1.Salzburg 0.059924 0.033834 1.771 0.077
L1.Steiermark 0.228090 0.044321 5.146 0.000
L1.Tirol 0.495952 0.035948 13.796 0.000
L1.Vorarlberg 0.049289 0.030944 1.593 0.111
L1.Wien -0.047890 0.056945 -0.841 0.400
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155250 0.053081 2.925 0.003
L1.Burgenland -0.009995 0.036339 -0.275 0.783
L1.Kärnten 0.065104 0.019353 3.364 0.001
L1.Niederösterreich 0.201031 0.076025 2.644 0.008
L1.Oberösterreich -0.067215 0.072555 -0.926 0.354
L1.Salzburg 0.220555 0.038622 5.711 0.000
L1.Steiermark 0.115515 0.050594 2.283 0.022
L1.Tirol 0.081222 0.041036 1.979 0.048
L1.Vorarlberg 0.124335 0.035324 3.520 0.000
L1.Wien 0.115830 0.065004 1.782 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.352040 0.031005 11.354 0.000
L1.Burgenland 0.007112 0.021226 0.335 0.738
L1.Kärnten -0.024063 0.011304 -2.129 0.033
L1.Niederösterreich 0.224694 0.044407 5.060 0.000
L1.Oberösterreich 0.168745 0.042380 3.982 0.000
L1.Salzburg 0.049706 0.022560 2.203 0.028
L1.Steiermark -0.015496 0.029553 -0.524 0.600
L1.Tirol 0.111422 0.023970 4.648 0.000
L1.Vorarlberg 0.073417 0.020633 3.558 0.000
L1.Wien 0.053447 0.037970 1.408 0.159
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.042817 0.157651 0.191289 0.161804 0.129198 0.121075 0.068375 0.230072
Kärnten 0.042817 1.000000 0.001048 0.131748 0.042822 0.098537 0.428405 -0.051260 0.102849
Niederösterreich 0.157651 0.001048 1.000000 0.342313 0.159309 0.308226 0.123726 0.188784 0.335002
Oberösterreich 0.191289 0.131748 0.342313 1.000000 0.234280 0.337502 0.177998 0.178146 0.268767
Salzburg 0.161804 0.042822 0.159309 0.234280 1.000000 0.150131 0.135393 0.150617 0.139638
Steiermark 0.129198 0.098537 0.308226 0.337502 0.150131 1.000000 0.162231 0.146295 0.086846
Tirol 0.121075 0.428405 0.123726 0.177998 0.135393 0.162231 1.000000 0.120023 0.163067
Vorarlberg 0.068375 -0.051260 0.188784 0.178146 0.150617 0.146295 0.120023 1.000000 0.012577
Wien 0.230072 0.102849 0.335002 0.268767 0.139638 0.086846 0.163067 0.012577 1.000000